package proyecto;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Image;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JLabel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Image;
import java.io.File;
import java.util.Timer;

import javax.swing.ImageIcon;


public class Window extends JFrame {

	String rutaactual;
	final String map1;
	
	String map2, map3, map4, map5, map6, cha1, cha2, end,mapsorpresa;
	
	Boolean evento;
	
	private mapa mapa;
	
	private File f;
	
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {

					Window frame = new Window();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Window() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1393, 770);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		final JLabel lblNewLabel = new JLabel("");
		final JLabel lblNewLabe2 = new JLabel("");
		panel.add(lblNewLabel);
		panel.add(lblNewLabe2);
		
		String sol;
		
		evento=true;
	
		
		//cargarimagen
		
		//mapa1
		 ImageIcon image1 = new javax.swing.ImageIcon( "imagenes/map1.png" );
		 map1="imagenes/map1.png";
		 Image imagen1 = image1.getImage();
		 final ImageIcon iconoEscalado1 = new ImageIcon (imagen1.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		
		//mapa2
		 ImageIcon image2 = new javax.swing.ImageIcon( "imagenes/map2.png" );
		 map2="imagenes/map2.png";
		 Image imagen2 = image2.getImage();
		 final ImageIcon iconoEscalado2 = new ImageIcon (imagen2.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//mapa3
		 ImageIcon image3 = new javax.swing.ImageIcon( "imagenes/map3.png" );
		 map3="imagenes/map3.png";
		 Image imagen3 = image3.getImage();
		 final ImageIcon iconoEscalado3 = new ImageIcon (imagen3.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//mapa4
		 ImageIcon image4 = new javax.swing.ImageIcon( "imagenes/map4.png" );
		 map4="imagenes/map4.png";
		 Image imagen4 = image4.getImage();
		 final ImageIcon iconoEscalado4 = new ImageIcon (imagen4.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//mapa5
		 ImageIcon image5 = new javax.swing.ImageIcon( "imagenes/map5.png" );
		 map5="imagenes/map5.png";
		 Image imagen5 = image5.getImage();
		 final ImageIcon iconoEscalado5 = new ImageIcon (imagen5.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//mapa6
		 ImageIcon image6 = new javax.swing.ImageIcon( "imagenes/map6.png" );
		 map6="imagenes/map6.png";
		 Image imagen6 = image6.getImage();
		 final ImageIcon iconoEscalado6 = new ImageIcon (imagen6.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//challenger1
		 ImageIcon image7 = new javax.swing.ImageIcon( "imagenes/Challenge.png" );
		 cha1="imagenes/Challenge.png";
		 Image imagen7 = image7.getImage();
		 final ImageIcon iconoEscalado7 = new ImageIcon (imagen7.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//challenger2
		 ImageIcon image8 = new javax.swing.ImageIcon( "imagenes/Challenge2.png" );
		 cha2="imagenes/Challenge2.png";
		 Image imagen8 = image8.getImage();
		 final ImageIcon iconoEscalado8 = new ImageIcon (imagen8.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//dead end
		 ImageIcon image9 = new javax.swing.ImageIcon( "imagenes/deadend.png" );
		 end="imagenes/deadend.png";
		 Image imagen9 = image9.getImage();
		 final ImageIcon iconoEscalado9 = new ImageIcon (imagen9.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		//mapa sorpresa
		 ImageIcon imagesorpresa = new javax.swing.ImageIcon( "imagenes/map1.png" );
		 mapsorpresa="imagenes/deadend.png";
		 Image imagensorpresa = imagesorpresa.getImage();
		 final ImageIcon iconoEscaladosorpresa = new ImageIcon (imagensorpresa.getScaledInstance(800,700,Image.SCALE_SMOOTH));
		 
		 
		JButton btnNewButton = new JButton("Mapa 1\r\n");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				
				lblNewLabel.setIcon(iconoEscalado1);
				rutaactual=map1;
				
			}
		});
		
		JButton btnNewButton_1 = new JButton("Mapa 2\r\n");
		
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblNewLabel.setIcon(iconoEscalado2);
				
				rutaactual=map2;
			}
		});
		
		JButton btnMapa = new JButton("Mapa 3\r\n");
		btnMapa.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblNewLabel.setIcon(iconoEscalado3);
				
				rutaactual=map3;
			}
		});
		
		JButton btnChallenge = new JButton("Challenge 1\r\n");
		btnChallenge.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblNewLabel.setIcon(iconoEscalado7);
				
				rutaactual=cha1;
			}
		});
		
		JButton btnChallenge_1 = new JButton("Challenge 2\r\n");
		btnChallenge_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblNewLabel.setIcon(iconoEscalado8);
				
				rutaactual=cha2;
			}
		});
		
		JButton btnDeadEnd = new JButton("Dead end");
		btnDeadEnd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblNewLabel.setIcon(iconoEscalado9);
				
				rutaactual=end;
				
				
			}
		});
		
		JLabel lblMapas = new JLabel("MAPAS");
		
		JButton btnMapa_1 = new JButton("Mapa 4");
		btnMapa_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblNewLabel.setIcon(iconoEscalado4);
				
				rutaactual=map4;
			}
		});
		
		JButton btnMapa_2 = new JButton("Mapa 5");
		btnMapa_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblNewLabel.setIcon(iconoEscalado5);
				
				rutaactual=map5;
			}
		});
		
		JButton btnMapa_3 = new JButton("Mapa 6");
		btnMapa_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblNewLabel.setIcon(iconoEscalado6);
				
				rutaactual=map6;
			}
		});
		
		JButton btnNewButton_2 = new JButton("Play");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				

		        f =new File (rutaactual);
		        mapa = new mapa(f);
		        
				Start main = new Start(mapa,rutaactual);
			    
			while(main.fin==false)	{
				
				System.out.print(main.fin);
			}
			
		    ImageIcon ima = new javax.swing.ImageIcon( "solvedMaps/map4_Sol.png" );
		    Image ima2 = ima.getImage();
		    ImageIcon iconoEscalado = new ImageIcon (ima2.getScaledInstance(800,700,Image.SCALE_SMOOTH));
				 
		  lblNewLabel.setIcon(iconoEscalado);
							
		  System.out.println("mamones");
			}
		});
		btnNewButton_2.setIcon(new ImageIcon(Window.class.getResource("/javax/swing/plaf/metal/icons/ocean/paletteClose.gif")));
		
		JButton btnMapaSorpresa = new JButton("Mapa Sorpresa");
		btnMapaSorpresa.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				lblNewLabel.setIcon(iconoEscaladosorpresa);
				
				rutaactual=mapsorpresa;
				
			}
		});
		
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 1108, GroupLayout.PREFERRED_SIZE)
					.addGap(79)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblMapas)
						.addComponent(btnNewButton_1)
						.addComponent(btnMapa)
						.addComponent(btnMapa_1)
						.addComponent(btnMapa_2)
						.addComponent(btnMapa_3)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
							.addComponent(btnNewButton_2)
							.addComponent(btnNewButton))
						.addComponent(btnChallenge)
						.addComponent(btnChallenge_1)
						.addComponent(btnDeadEnd)
						.addComponent(btnMapaSorpresa))
					.addGap(69))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(31)
					.addComponent(btnNewButton_2)
					.addGap(70)
					.addComponent(lblMapas)
					.addGap(56)
					.addComponent(btnNewButton)
					.addGap(18)
					.addComponent(btnNewButton_1)
					.addGap(18)
					.addComponent(btnMapa)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnMapa_1)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnMapa_2)
					.addGap(18)
					.addComponent(btnMapa_3)
					.addGap(52)
					.addComponent(btnChallenge)
					.addGap(18)
					.addComponent(btnChallenge_1)
					.addGap(18)
					.addComponent(btnDeadEnd)
					.addPreferredGap(ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
					.addComponent(btnMapaSorpresa)
					.addGap(32))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 700, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(19, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
}
